<template>
	<view class="goods-item">
	  <view class="goods-item-left">
      <radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioHandler" ></radio>
	    <image :src="goods.goods_small_logo || defaultImage"></image>
	  </view>
	  <view class="goods-item-right">
	    <!--商品标题-->
	    <view class="goods-title">
	      {{goods.goods_name}}
	    </view>
	    <!--商品标题-->
      <view class="goods-info-box">
             <uni-number-box :min="0" :value="goods.goods_count" v-if="showNum" @change="handlerChange"></uni-number-box>
             <view class="goods-price">
               ￥{{goods.goods_price | tofixed}}
             </view>
      </view>
	 
	  </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				
			};
		},
    props:{
      goods:{
        type:Object
      },
      showRadio:{
        type:Boolean,
        default:false
      },
      showNum:{
        type:Boolean,
        default:false
      }
    },
    filters:{
      // 把数字处理为带两位小数点的数字
        tofixed(num) {
          return Number(num).toFixed(2)
        }
    },
    methods:{
      radioHandler(){
        //子传父
        this.$emit('radio-change',{goods_id:this.goods.goods_id,goods_state:!this.goods.goods_state});
      },
      handlerChange(val){
        this.$emit('num-change',{goods_id:this.goods.goods_id,goods_count:+val});
      }
    }
	}
</script>

<style lang="scss">
 .goods-item{
    padding: 10px 5px;
    border-bottom: 1px solid #efefef;
    display: flex;
    .goods-item-left{
      display: flex;
      margin-right: 5px;
      align-items: center;//类里面的每一个元素都纵向居中
      justify-content: space-between;//类里面的每一个元素都分散对齐
      image{
        width: 100px;
        height: 100px;
        display: block;
      }
      margin-right: 5px;
    }
    .goods-item-right{
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      .goods-title{
        font-size: 12px;
      }
      .goods-info-box{
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex: 1;
        .goods-price{
          font-size: 16px;
          color: #c00000;
        }
      }
      
    }
  }
</style>
